[SPARK-33522][SQL] Improve exception messages while handling UnresolvedTableOrView#30475
[SPARK-33522][SQL] Improve exception messages while handling UnresolvedTableOrView#30475imback82 wants to merge 8 commits intoapache:masterfrom
Conversation
| sql("DROP TABLE testcat.db.notbl") | ||
| } | ||
| assert(ex.getMessage.contains("Table or view not found: testcat.db.notbl")) | ||
| assert(ex.getMessage.contains("Table or view not found for 'DROP TABLE': testcat.db.notbl")) |
There was a problem hiding this comment.
This message could be misleading since DROP TABLE supports table and a temporary view. To fix this, we can add allowPermanentView as the following and update Analyzer accordingly:
case class UnresolvedTableOrView(
multipartIdentifier: Seq[String],
commandName: String,
allowTempView: Boolean = true,
allowPermanentView: Boolean = true) extends LeafNode {
require(allowTempView || allowPermanentView)
override lazy val resolved: Boolean = false
override def output: Seq[Attribute] = Nil
}such that the exception message can be updated to
Table or temporary view not found for 'DROP TABLE': t.
One downside is that if t is resolved to a view, the message will become:
t is a permanent view. 'DROP TABLE' expects a table or temporary view.
instead of (current message):
Cannot drop a view with DROP TABLE. Please use DROP VIEW instead
, meaning it will lose the "hint" (which we can add it to Unresolved* if required).
@cloud-fan WDYT? If you are OK with introducing allowPermanentView, I can do it as a separate PR.
There was a problem hiding this comment.
Sorry I don't get it. In this case, testcat.db.notbl is not a permanent view, but a non-existing relation.
There was a problem hiding this comment.
When I read Table or view not found for 'DROP TABLE': t, it sounded like DROP TABLE also supports permanent views.
So, I was suggesting Table or temporary view not found for 'DROP TABLE': t since DROP TABLE requires either a table or temporary view. But, I guess Table or view not found sounds better if we want to point out the non-existing relation.
There was a problem hiding this comment.
since DROP TABLE requires either a table or temporary view
Do we have such a test case for v2 DROP TABLE?
There was a problem hiding this comment.
v2 DROP TABLE only handles ResolvedTable. If it's resolved to a view, it will be handled in ResolveSessionCatalog and tested here:
spark/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
Lines 1056 to 1070 in fdd6c73
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
|
Test build #131574 has finished for PR 30475 at commit
|
|
Test build #131609 has finished for PR 30475 at commit
|
|
Test build #131578 has finished for PR 30475 at commit
|
|
Test build #131686 has finished for PR 30475 at commit
|
|
retest this please |
|
Test build #131748 has finished for PR 30475 at commit
|
|
retest this please |
|
Test build #131802 has finished for PR 30475 at commit
|
|
Test build #131808 has finished for PR 30475 at commit
|
|
Test build #131813 has finished for PR 30475 at commit
|
cloud-fan
left a comment
There was a problem hiding this comment.
LGTM. Please fix the conflicts.
|
Test build #131872 has finished for PR 30475 at commit
|
|
retest this please |
|
GA passed, merging to master, thanks! |
|
Test build #131878 has finished for PR 30475 at commit
|
What changes were proposed in this pull request?
This PR proposes to improve the exception messages while
UnresolvedTableOrViewis handled based on this suggestion: #30321 (comment).Currently, when an identifier is resolved to a temp view when a table/permanent view is expected, the following exception message is displayed (e.g., for
SHOW CREATE TABLE):After this PR, the message will be:
Also, if an identifier is not resolved, the following exception message is currently used:
After this PR, the message will be:
or
Why are the changes needed?
To improve the exception message.
Does this PR introduce any user-facing change?
Yes, the exception message will be changed as described above.
How was this patch tested?
Updated existing tests.